<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class TaskComplete extends Model
{
    protected $table = "c_task_complete";

    /**
     * @param $data
     * @param $task_id
     * @return bool
     * 添加完成任务记录
     */
    public static function add($data, $task_id)
    {
        $task = new self();
        $date = date("Y-m-d", time());
        $task->date_at = $date;
        $task->task_id = $task_id;
        $task->work_id = $data['work_id'];
        return $task->save();
    }

    /**
     * @param $data
     * @return bool
     * 设置完成认为
     */
    public static function set($data)
    {
        $res = self::detail($data);
        if ($res) {
            return true;
        }
        $com = self::add($data, $data['type']);
        $group = GrowthNumberLog::add($data, $data['type']);
        if ($com && $group) {
            return true;
        }
    }

    /**
     * @param $data
     * @return mixed
     * 详情
     */
    public static function detail($data)
    {
        return self::where([['work_id', '=', $data['work_id']],["task_id",'=',$data['type']], ['date_at', '=', date("Y-m-d", time())]])->first();
    }
}
